﻿using ManaMaple.Auth.Interface;
using ManaMaple.DB.Entity;
using ManaMaple.Kit.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ManaMaple.Service.Base
{
    /// <summary>
    /// 公共服务
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class FoundService<T> where T : BaseEntity, new()
    {
        protected readonly IAuth _auth;
        /// <summary>
        /// 用户信息
        /// </summary>
        protected readonly CurrentUserModel CurrenUserInfo;
        public FoundService(IAuth auth)
        {
            this._auth = auth;
            this.CurrenUserInfo = this._auth.GetCurrentUser() ?? new CurrentUserModel();
        }

        protected void GetConnUpdataUserInfo(BaseEntity entity)
        {
            if (entity.Id <= 0)
            {
                entity.Crea = CurrenUserInfo.UserID;
                entity.CreaName = CurrenUserInfo.UserName;
                entity.CreaDtt = DateTime.Now;
            }
            entity.Uptr = CurrenUserInfo.UserID;
            entity.UptrName = CurrenUserInfo.UserName;
            entity.UptDtt = DateTime.Now;
        }
    }
}
